import random
print(help(random))
'''
#默认 0-1
print(random.random())
# 设定范围[1,8]
print(random.randint(1,8))
# 比randint 多了一个step 范围[1,8)
print(random.randrange(1,8))

#一个序列里选择
print(random.choice('hello'))
print(random.choice(['hello',12,'a',('ni','hao')]))
#在一个序列里选多个值
print(random.sample(range(5),3))
# 随机打乱一个序列的顺序
ret=list(range(1,5))
print(type(ret))
print('ret befor shuffle:',ret)
random.shuffle(ret)
print('ret after shuffle:',ret)
'''
#-------------------生成一个固定位数的验证码 数字加字母---------------
def genValidCode(len=5):
    vCode=[]
    # Gen all char and num
    for i in range(len):
        add_num=random.randrange(10)
        #print(type(add_num))
        add_alpha=chr(random.randrange(65,91))
        #print(type(add_alpha))
        vCode.append(add_num)
        vCode.append(add_alpha)
        vCode.append(add_alpha.lower())
        #print(vCode)
    # shuffle list
    random.shuffle(vCode)
    # get your length
    ret = random.sample(vCode,len)
    return  ret
print(genValidCode(5))